
let db = require('../utils/DB');//数据库
let to = require('../utils/await-to-js');
let { SUCCESS, ERROR } = require('../utils/result');//结果
let {HOST}=require('../utils/CONSTANT');

//人气好货
function popularityModel() {
    return async (req, res) => {
        let [err, data] = await to(db.query(`SELECT a.goods_id,b.goods_name,CONCAT(?,b.image_url) as image_url ,
        SUM(a.eval_start) as evalStartSum,COUNT(a.eval_start) as evalNum FROM goods_eval as a
        INNER JOIN goods_list as b
        ON a.goods_id=b.goods_id
        GROUP BY a.goods_id
        ORDER BY evalStartSum DESC
        LIMIT 8`,[HOST]));
        err ? ERROR(res, '人气好货失败', err) : SUCCESS(res, data);
    }
}

module.exports = popularityModel;